<template>
  <div class="app-container">
   <!-- 查询条件区域-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="机器人名称" prop="robot_name">
        <el-input
          v-model="queryParams.robot_name"
          placeholder="请输入机器人名称"
          clearable
          @keyup.enter.native="handleQuery"
          size="small"
        />
      </el-form-item>
      <el-form-item label="告警描述" prop="alarmDesc">
        <el-input
          v-model="queryParams.alarmDesc"
          placeholder="请输入告警描述"
          clearable
          @keyup.enter.native="handleQuery"
          size="small"
        />
      </el-form-item>
      <el-form-item label="告警时间">
        <el-date-picker
            v-model="queryParams.create_times"
            style="width: 215px" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
    </el-row>
    <!--增删改查按钮区域-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['nssc:alarm:remove']"
        >删除</el-button>
      </el-col>
    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!--数据列表区域-->
    <el-table v-loading="loading" :data="listAlarmData" @selection-change="handleSelectionChange" :cell-style="{borderColor:'rgb(1 5 43)'}" :header-cell-style="{borderColor: 'rgb(1 5 43)'}">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="机器人名称" align="center" prop="robot_name"/>
<!--      <el-table-column label="参数名称" align="center" prop="param_name" width="160" />&ndash;&gt;-->
      <el-table-column label="告警描述" align="center" prop="alarminfo" :show-overflow-tooltip="true"/>
      <el-table-column label="告警时间" align="center" prop="alarmtime"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  width="220">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['nssc:alarm:removedata']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--列表分页区域-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList" style="background:rgb(1 5 43);"
    />
  </div>
</template>
<script>
import "@/assets/styles/robt-bg.css";
import {listAlarmData} from "@/api/nssc/alarm/alarmData/alarm";
import {delsAlarm} from "@/api/nssc/alarm/alarmSet/alarm";
export default {
  name: "AlarmData",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      //初始化列表数据
      listAlarmData: [],
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        robot_name: undefined,
        create_times: [/*this.dealWithTime(new Date()), this.dealWithTime(new Date())*/],
        alarmDesc: undefined
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList(); /** 初始化告警数据列表 */
  },
  methods: {
    //日期格式化
    dealWithTime(date) {
      let Y = date.getFullYear()
      let M = date.getMonth() + 1 - 0 >= 10 ? Number(date.getMonth()) + 1 : '0' + (Number(date.getMonth()) + 1)
      let D = date.getDate() > 10 ? date.getDate():"0"+date.getDate();
      return Y + '-' + M + '-' + D
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除选中的数据项？').then(function() {
        return delsAlarm(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }, /**初始化告警数据列表*/
    getList() {
      this.loading = true;
      listAlarmData(this.queryParams).then(response => {
        this.listAlarmData = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },// 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },// 表单重置
    reset() {
      this.form = {
      };
      this.resetForm("form");
    },/** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.create_times= [this.dealWithTime(new Date()), this.dealWithTime(new Date())];
      this.queryParams.robot_name=null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
  }
};
</script>
